package two.chapter_1.c1_3;

import edu.princeton.cs.algs4.StdOut;

import java.io.File;


public class Ex1_3_43 {

    public static void main(String[] args) {
        String path="/Users/wind/Desktop/filelevel";
        File file=new File(path);
        Queue<String> q=new LinkedQueue<>();
        print(q,0,file);

        for (String filename:q){
            StdOut.println(filename);
        }
    }

    private static void print(Queue<String> q,int level,File file) {
        StringBuilder sBuilder=new StringBuilder();
        for (int i=0;i<level;i++){
            sBuilder.append("   ");
        }
        q.enqueue(sBuilder.toString()+file.getName());
        if (file.isDirectory()){
            File [] files=file.listFiles();
            level++;
            for (int i=0;i<files.length;i++){
                if (!files[i].getName().startsWith("."))
                    print(q,level,files[i]);
            }
        }

    }


}
